<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>Spring-Boot拥抱MyBatis及Redis ~ - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-07-01 10:26">
      July 1, 2019 am
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.9k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      48
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-Spring-Boot拥抱MyBatis及Redis"><a href="#学习笔记-Spring-Boot拥抱MyBatis及Redis" class="headerlink" title="学习笔记 : Spring Boot拥抱MyBatis及Redis ~"></a>学习笔记 : Spring Boot拥抱MyBatis及Redis ~</h2><h3 id="Spring-Boot集成MyBatis"><a href="#Spring-Boot集成MyBatis" class="headerlink" title="Spring Boot集成MyBatis"></a>Spring Boot集成MyBatis</h3><p><em>下面通过使用<code>Spring Boot</code>开发一个基于<code>SSM</code>的框架的应用,并通过一个简单的用户信息查询为例,记录如何在Spring Boot中使用<code>MyBatis</code> ~</em></p>
<ol>
<li><p><em>tb_user.sql : 用户信息数据表</em></p>
<div class="hljs"><pre><code class="hljs sql"><span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> tb_user
(
    <span class="hljs-keyword">id</span>     <span class="hljs-built_in">int</span> auto_increment primary <span class="hljs-keyword">key</span>,
    <span class="hljs-keyword">name</span>   <span class="hljs-built_in">varchar</span>(<span class="hljs-number">15</span>) <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span>,
    gender <span class="hljs-built_in">char</span>        <span class="hljs-literal">null</span>,
    email  <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-literal">null</span>
);</code></pre></div>
</li>
<li><p><em>pom.xml</em></p>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://maven.apache.org/POM/4.0.0"</span> <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span>
         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- lookup parent from repository --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.1.6.RELEASE<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">relativePath</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>pers.huangyuhui<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>0.0.1-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>springboot_redis<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">description</span>&gt;</span>Demo project for Spring Boot<span class="hljs-tag">&lt;/<span class="hljs-name">description</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">java.version</span>&gt;</span>11<span class="hljs-tag">&lt;/<span class="hljs-name">java.version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- Web --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- MyBatis --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis.spring.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- Redis --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- MySQL --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>runtime<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- mvn package --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span></code></pre></div>
</li>
<li><p><em>SpringbootRedisApplication.java : Spring Boot启动类</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis;

<span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;
<span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;

<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SpringbootRedisApplication</span> </span>&#123;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;
        SpringApplication.run(SpringbootRedisApplication<span class="hljs-class">.<span class="hljs-keyword">class</span>, <span class="hljs-title">args</span>)</span>;
    &#125;

&#125;</code></pre></div>
</li>
<li><p><em>application.properties : Spring Boot配置文件</em></p>
<div class="hljs"><pre><code class="hljs t">#JDBC-Connection Configuration Information
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false&amp;serverTimezone=UTC&amp;allowPublicKeyRetrieval=true
spring.datasource.username=xxxxxx
spring.datasource.password=xxxxxx
#Logging Configuration Information
logging.level.pers.huangyuhui.redis=debug</code></pre></div>
</li>
<li><p><em>User.java : 用户信息实体类</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis.bean;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot_redis
 * <span class="hljs-doctag">@description</span>: 用户信息
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 7/1/2019-7:08 AM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> </span>&#123;

    <span class="hljs-keyword">private</span> Integer id;
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> String gender;
    <span class="hljs-keyword">private</span> String email;

    <span class="hljs-comment">//getter and setter</span>
    ······
&#125;</code></pre></div>
</li>
<li><p><em>UserMapper.java : 操控用户数据表信息</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis.dao;

<span class="hljs-keyword">import</span> org.apache.ibatis.annotations.Mapper;
<span class="hljs-keyword">import</span> org.apache.ibatis.annotations.Select;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.bean.User;

<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot_redis
 * <span class="hljs-doctag">@description</span>: Dao层-操控用户信息
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 7/1/2019-7:12 AM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-meta">@Mapper</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">UserMapper</span> </span>&#123;

    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> 7/1/2019 查询所有用户信息</span>
    <span class="hljs-meta">@Select</span>(<span class="hljs-string">"select * from tb_user"</span>)
    <span class="hljs-function">List&lt;User&gt; <span class="hljs-title">selectAll</span><span class="hljs-params">()</span></span>;

    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> 7/1/2019 根据id删除指定用户信息</span>
    <span class="hljs-meta">@Delete</span>(<span class="hljs-string">"Delete from tb_user where id = #&#123;id&#125;"</span>)
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">deleteById</span><span class="hljs-params">(Integer id)</span></span>;
&#125;</code></pre></div>
</li>
<li><p><em>UserService.java : 操控用户信息</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis.service;

<span class="hljs-keyword">import</span> pers.huangyuhui.redis.bean.User;

<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot_redis
 * <span class="hljs-doctag">@description</span>: Service层-操控用户信息
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 7/1/2019-7:25 AM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">UserService</span> </span>&#123;

    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> 7/1/2019 获取或有用户信息</span>
    <span class="hljs-function">List&lt;User&gt; <span class="hljs-title">findAll</span><span class="hljs-params">()</span></span>;

     <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> 7/1/2019 根据id删除指定用户信息</span>
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">delete</span><span class="hljs-params">(Integer id)</span></span>;
&#125;</code></pre></div>
</li>
<li><p><em>UserServiceImpl.java : UserService.java的实现类</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis.service.impl;

<span class="hljs-keyword">import</span> org.springframework.stereotype.Service;
<span class="hljs-keyword">import</span> org.springframework.transaction.annotation.Transactional;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.bean.User;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.dao.UserMapper;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.service.UserService;

<span class="hljs-keyword">import</span> javax.annotation.Resource;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot_redis
 * <span class="hljs-doctag">@description</span>: UserService的实现类
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 7/1/2019-7:27 AM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-meta">@Service</span>
<span class="hljs-meta">@Transactional</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">UserService</span> </span>&#123;

    <span class="hljs-comment">//注入Mapper对象</span>
    <span class="hljs-meta">@Resource</span>
    <span class="hljs-keyword">private</span> UserMapper userMapper;

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title">findAll</span><span class="hljs-params">()</span> </span>&#123;
        <span class="hljs-keyword">return</span> userMapper.selectAll();
    &#125;

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">delete</span><span class="hljs-params">(Integer id)</span> </span>&#123;
        userMapper.deleteById(id);
    &#125;

&#125;</code></pre></div>
</li>
<li><p><em>UserController.java : 用户信息控制器</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.redis.controller;

<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Controller;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.PathVariable;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.ResponseBody;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.bean.User;
<span class="hljs-keyword">import</span> pers.huangyuhui.redis.service.UserService;

<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@project</span>: springboot_redis
 * <span class="hljs-doctag">@description</span>: 用户控制器
 * <span class="hljs-doctag">@author</span>: 黄宇辉
 * <span class="hljs-doctag">@date</span>: 7/1/2019-7:28 AM
 * <span class="hljs-doctag">@version</span>: 1.0
 * <span class="hljs-doctag">@website</span>: https://yubuntu0109.github.io/
 */</span>
<span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">"/user"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserController</span> </span>&#123;

    <span class="hljs-comment">//注入业务对象</span>
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> UserService userService;

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@description</span>: 获取所有用户信息
     * <span class="hljs-doctag">@date</span>: 2019-07-01 8:16 AM
     * <span class="hljs-doctag">@return</span>: java.util.List&lt;pers.huangyuhui.redis.bean.User&gt;
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">"/getUserList"</span>)
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title">getUserList</span><span class="hljs-params">()</span> </span>&#123; <span class="hljs-keyword">return</span> userService.findAll(); &#125;

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@description</span>: 删除指定id的好友信息
     * <span class="hljs-doctag">@param</span>: id
     * <span class="hljs-doctag">@date</span>: 2019-07-01 12:51 PM
     * <span class="hljs-doctag">@return</span>: void
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">"/deleteUser/&#123;id&#125;"</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">deleteUser</span><span class="hljs-params">(@PathVariable Integer id)</span> </span>&#123; userService.delete(id); &#125;

&#125;</code></pre></div>
</li>
<li><p><em>userList.html : 用户信息列表页面 (将EasyUI框架的资源文件拷贝到src/main/resource下的static文件夹下,并在static文件夹中创建<code>userList.html</code>页面文件)</em></p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>用户信息列表页面<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- CSS --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"easyui/themes/metro/easyui.css"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- JS --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"easyui/jquery.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"easyui/jquery.easyui.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"easyui/themes/locale/easyui-lang-zh_CN.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="javascript">
        $(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>&#123;
            $(<span class="hljs-string">'#graid'</span>).datagrid(&#123;
                <span class="hljs-attr">url</span>: <span class="hljs-string">'user/getUserList'</span>,
                <span class="hljs-attr">fit</span>: <span class="hljs-literal">true</span>,
                <span class="hljs-attr">columns</span>: [[
                    &#123;<span class="hljs-attr">field</span>: <span class="hljs-string">'id'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'编号'</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">100</span>&#125;,
                    &#123;<span class="hljs-attr">field</span>: <span class="hljs-string">'name'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'姓名'</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">100</span>&#125;,
                    &#123;<span class="hljs-attr">field</span>: <span class="hljs-string">'gender'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'性别'</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">100</span>&#125;,
                    &#123;<span class="hljs-attr">field</span>: <span class="hljs-string">'email'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'邮箱'</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">200</span>&#125;
                ]]
            &#125;);
        &#125;);
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-comment">&lt;!-- 用户信息列表 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"graid"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>
</li>
<li><p><em>启动Spring Boot项目,在浏览器中输入访问地址 : <code>http://localhost:8080/userList.html</code>后,显示效果参考下图 :</em><br><img src="/2019/07/01/Spring-Boot%E6%8B%A5%E6%8A%B1MyBatis%E5%8F%8ARedis/UserListView.PNG" srcset="/img/loading.gif" alt=" "></p>
</li>
</ol>
<p><em>紧接着刷新页面三次,其控制台打印的日志信息如下所示,发现每刷新一次页面都会执行一次查询数据库操作,<code>但如果将列表数据缓冲到Redis后,会发现控制台只会出现一次查询数据库的日志信息哟 !</code></em></p>
<div class="hljs"><pre><code class="hljs angelscript"><span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">49.868</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-3</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt;  Preparing: select * <span class="hljs-keyword">from</span> tb_user 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">49.869</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-3</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt; Parameters: 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">49.871</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-3</span>] p.h.redis.dao.UserMapper.selectAll       : &lt;==      Total: <span class="hljs-number">5</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">54.250</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-5</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt;  Preparing: select * <span class="hljs-keyword">from</span> tb_user 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">54.250</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-5</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt; Parameters: 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">54.253</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-5</span>] p.h.redis.dao.UserMapper.selectAll       : &lt;==      Total: <span class="hljs-number">5</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">57.251</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt;  Preparing: select * <span class="hljs-keyword">from</span> tb_user 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">57.251</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt; Parameters: 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">11</span>:<span class="hljs-number">41</span>:<span class="hljs-number">57.256</span> DEBUG <span class="hljs-number">7844</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : &lt;==      Total: <span class="hljs-number">5</span>

Process finished with exit code <span class="hljs-number">-1</span></code></pre></div>



<h3 id="Spring-Boot集成Redis"><a href="#Spring-Boot集成Redis" class="headerlink" title="Spring Boot集成Redis"></a>Spring Boot集成Redis</h3><p><em>Redis是一个完全开源的,遵守BSD协议的,内存中的数据结构存储,它既可以作为<code>数据库</code>,也可以作为<code>缓存</code>和<code>消息代理</code>. 通常在企业中常将其作为缓存使用哟~ 接下来在Spring Boot集成MyBatis示例程序基础上将列表数据缓存到Redis中,详细步骤如下 :</em></p>
<ol>
<li><p><em>在<code>pom.xml</code>中添加Spring Boot支持Redis的依赖</em></p>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span></code></pre></div></li>
<li><p><em>在<code>SpringbootRedisApplication.java</code>中添加<code>@EnableCaching</code>注解来开启缓存</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-meta">@EnableCaching</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SpringbootRedisApplication</span> </span>&#123;
    <span class="hljs-comment">//······</span>
&#125;</code></pre></div>
</li>
<li><p><em>在业务逻辑类<code>UserServiceImpl.java</code>的方法上添加<code>@Cacheable</code>注解来支持Redis缓存</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-meta">@Override</span>
<span class="hljs-meta">@Cacheable</span>(value = <span class="hljs-string">"UserCatch"</span>, key = <span class="hljs-string">"'user.selectAll'"</span>)
<span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title">findAll</span><span class="hljs-params">()</span> </span>&#123;
    <span class="hljs-keyword">return</span> userMapper.selectAll();
&#125;</code></pre></div>
</li>
<li><p><em>为便于数据的传输,将实体类<code>User.java</code>实现序列化接口Serializable</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Serializable</span> </span>&#123;
    <span class="hljs-comment">//······</span>
&#125;</code></pre></div>
</li>
<li><p><em>在<code>application.properties</code>中指定<code>Redis</code>缓存主机地址及端口号. 我使用的是Windows的Redis发行版哟,其学习笔记 : <a href="https://yubuntu0109.github.io/2019/06/25/Hi-Redis/">https://yubuntu0109.github.io/2019/06/25/Hi-Redis/</a></em></p>
<div class="hljs"><pre><code class="hljs t">#Redis Configuration Infromation
spring.redis.host=localhost
spring.redis.port=6379</code></pre></div>
</li>
<li><p><em>启动Redis服务,并启动Spring Boot项目,在浏览器地址栏中输入访问地址 : <code>http://localhost:8080/userList.html</code>后,不断刷新页面,其控制台打印的日志信息如下,结论 : 在没有使用Redis缓存之前,每刷新一次页面,都会执行一次查询数据库的操作,添加缓存后,会发现日志信息中只出现了一次查询语句,这也就说明所配置的Redis缓存已经生效啦 ~</em></p>
<div class="hljs"><pre><code class="hljs angelscript"><span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">06.945</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet <span class="hljs-string">'dispatcherServlet'</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">06.946</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] o.s.web.servlet.DispatcherServlet        : Initializing Servlet <span class="hljs-string">'dispatcherServlet'</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">06.951</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] o.s.web.servlet.DispatcherServlet        : Completed initialization <span class="hljs-keyword">in</span> <span class="hljs-number">5</span> ms

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.218</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] io.lettuce.core.EpollProvider            : Starting without optional epoll library

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.218</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] io.lettuce.core.KqueueProvider           : Starting without optional kqueue library

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.701</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] com.zaxxer.hikari.HikariDataSource       : HikariPool<span class="hljs-number">-1</span> - Starting...
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.791</span>  INFO <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] com.zaxxer.hikari.HikariDataSource       : HikariPool<span class="hljs-number">-1</span> - Start completed.

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.805</span> DEBUG <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt;  Preparing: select * <span class="hljs-keyword">from</span> tb_user 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.815</span> DEBUG <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt; Parameters: 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">12</span>:<span class="hljs-number">43</span>:<span class="hljs-number">07.836</span> DEBUG <span class="hljs-number">1984</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-7</span>] p.h.redis.dao.UserMapper.selectAll       : &lt;==      Total: <span class="hljs-number">7</span>


Process finished with exit code <span class="hljs-number">-1</span></code></pre></div>


</li>
</ol>
<h4 id="清除Redis缓存"><a href="#清除Redis缓存" class="headerlink" title="清除Redis缓存"></a>清除Redis缓存</h4><p><em>当执行添加,更新和删除操作后,数据库中的数据会发生变化,继而Redis缓存中的数据同样也需要进行相应的变化,为了保证Redis缓存中的数据与数据库中的一致,通常需要在执行<code>添加</code>,<code>更新</code>和<code>删除</code>操作之前清除缓存,然后再下一次执行查询操作时,将新的数据存储到Redis缓存中 .</em></p>
<p><em>若要实现清除缓存的功能,只需在相应的方法中使用<code>@CacheEvict</code>注解即可,下面以案例程序中的删除用户功能为例,在用户业务逻辑类的<code>deleteUser()</code>方法上添加<code>@CacheEvict</code>注解 :</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-meta">@Override</span>
<span class="hljs-meta">@CacheEvict</span>(value = <span class="hljs-string">"UserCatch"</span>, key = <span class="hljs-string">"'user.selectAll'"</span>)
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">delete</span><span class="hljs-params">(Integer id)</span> </span>&#123;
    userMapper.deleteById(id);
&#125;</code></pre></div>

<p><em>重启Spring Boot项目,在浏览器地址栏中输入访问地址 : <code>http://localhost:8080/user/deleteUser/5</code>, <code>../6</code> , <code>../7</code>删除id为5,6,7的用户信息后再查询用户列表信息 : <code>http://localhost:8080/userList.html</code>,其控制台打印的日志信息如下 :</em></p>
<div class="hljs"><pre><code class="hljs angelscript"><span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">13</span>:<span class="hljs-number">45.143</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt;  Preparing: Delete <span class="hljs-keyword">from</span> tb_user where id = ? 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">13</span>:<span class="hljs-number">45.160</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt; Parameters: <span class="hljs-number">5</span>(Integer)
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">13</span>:<span class="hljs-number">45.162</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] p.h.redis.dao.UserMapper.deleteById      : &lt;==    Updates: <span class="hljs-number">1</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">13</span>:<span class="hljs-number">45.331</span>  INFO <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] io.lettuce.core.EpollProvider            : Starting without optional epoll library
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">13</span>:<span class="hljs-number">45.332</span>  INFO <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-1</span>] io.lettuce.core.KqueueProvider           : Starting without optional kqueue library

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">16.033</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt;  Preparing: Delete <span class="hljs-keyword">from</span> tb_user where id = ? 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">16.033</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt; Parameters: <span class="hljs-number">6</span>(Integer)
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">16.034</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.deleteById      : &lt;==    Updates: <span class="hljs-number">1</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">31.217</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-6</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt;  Preparing: Delete <span class="hljs-keyword">from</span> tb_user where id = ? 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">31.218</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-6</span>] p.h.redis.dao.UserMapper.deleteById      : ==&gt; Parameters: <span class="hljs-number">7</span>(Integer)
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">31.219</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-6</span>] p.h.redis.dao.UserMapper.deleteById      : &lt;==    Updates: <span class="hljs-number">1</span>

<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">47.353</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt;  Preparing: Select * <span class="hljs-keyword">from</span> tb_user 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">47.353</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.selectAll       : ==&gt; Parameters: 
<span class="hljs-number">2019</span><span class="hljs-number">-07</span><span class="hljs-number">-01</span> <span class="hljs-number">18</span>:<span class="hljs-number">15</span>:<span class="hljs-number">47.377</span> DEBUG <span class="hljs-number">14764</span> --- [nio<span class="hljs-number">-8080</span>-exec<span class="hljs-number">-4</span>] p.h.redis.dao.UserMapper.selectAll       : &lt;==      Total: <span class="hljs-number">4</span>

Process finished with exit code <span class="hljs-number">-1</span></code></pre></div>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Redis/">Redis</a>
                    
                      <a class="hover-with-bg" href="/tags/MyBatis/">MyBatis</a>
                    
                      <a class="hover-with-bg" href="/tags/Spring-Boot/">Spring Boot</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/07/10/Java%E7%88%AC%E8%99%AB%E4%B9%8BHttpClient/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Java爬虫之HttpClient</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/06/30/Spring-Boot%E4%B9%8B%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/">
                        <span class="hidden-mobile">Spring Boot之文件上传与下载</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Spring-Boot拥抱MyBatis及Redis ~&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
